import './detail.css';
import {Link} from 'react-router'

import {connect} from 'react-redux';
import Panel from './../../elements/Panel'
import {URL, md5Url} from '../../libs/Url';
import {Config, Fetch} from '../../libs/';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';
import Header from '../../components/Header';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'

export default  React.createClass({
    getInitialState(){
        return {};
    },
    componentDidMount(){
        Promise.all([
            Fetch(URL.HOMEWORK_GET, {
                body: {
                    homeworkid: this.props.params.id
                }
            }),
            Fetch(URL.Get_USER)
        ])
            .then(res=> {
                console.log(res);
                this.setState({
                    homework: res[0].homework,
                    teacher: res[1].user
                })
            })
            .catch(e=> {
                console.log(e);
            });
    },
    render(){
        var homework = this.state.homework || {}, state = this.state;
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: Config.MENUS_ABSOLUTE.HOME, label: '首页'},
                    {url: Config.MENUS_ABSOLUTE.HOMEWORK, label: '作业列表'},
                    {label: '详情'},
                ]}></BreadcrumbNavigation>
                <Panel>
                    <Header>作业详情</Header>
                    <div className="formBody">
                        <form className="form-horizontal">
                            <div className="form-group">
                                <label className="col-sm-2 control-label">科目：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}>{homework.subject && homework.subject.name}</div>
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">教师：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}>{state.teacher && state.teacher.name}</div>
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">详情：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}>{homework.comment}</div>
                                </div>
                            </div>
                            {
                                homework.fileds ? <div className="form-group">
                                    <label className="col-sm-2 control-label">附件：</label>
                                    <div className="col-sm-10">
                                        <div style={{paddingTop: '7px'}}><a
                                            href={'/api/image/' + homework.fileds}>附件</a>
                                        </div>
                                    </div>
                                </div> : null
                            }
                            <hr/>
                            <div className="form-group">
                                <div className="row">
                                    <label className="col-sm-2 control-label">推送班级：</label>
                                    <div className="col-sm-10">
                                        <ul className="homeword-set">
                                            <li><b>{homework.class && homework.class.name}</b> <span
                                                className="text-success">{homework.time} </span></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div className="form-group">
                                <div className="row">
                                    <label className="col-sm-2 control-label"></label>
                                    <div className="col-sm-10">
                                        <span>说明：设置作业要推送的班级，并关联课程表时间，作业将在当天上课30分钟后可进行查看</span>
                                    </div>
                                </div>

                            </div>
                            <div className="form-group submit">
                                <div className="col-sm-8 col-md-offset-2">
                                    <Link
                                        to={
                                            Config.MENUS_ABSOLUTE.HOMEWORK_UPDATE.replace(':id', homework.homeworkid)
                                        }
                                        className="btn btn-success " type="button">
                                        编辑
                                    </Link>
                                </div>
                            </div>
                        </form>
                    </div>
                </Panel>
            </div>
        )
    }
});
